package com.generate.controller;

import com.generate.param.GenerateParam;
import com.generate.service.CodeGeneratorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * @author ytj
 * @date 2021/5/31
 */
@Controller
public class IndexController {
    @Autowired
    private CodeGeneratorService codeGenerator;

    @GetMapping("/index")
    public String index(){
        return "index";
    }

    @PostMapping("/info")
    @ResponseBody
    public String info(GenerateParam generateParam, HttpServletResponse response){
        codeGenerator.codeGenerator(generateParam);
        this.codeGenerator.download(generateParam.getParent(),response);
        return "代码生成成功";
    }
}
